package com.quiz;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Color;
import android.view.MotionEvent;
import android.view.SurfaceHolder;
import android.view.SurfaceView;
import android.view.View;
import android.view.View.OnTouchListener;

public class AnimePanel extends SurfaceView implements SurfaceHolder.Callback,
		OnTouchListener {

	Bitmap bitmap;
	ViewThread thread;

	int xp = 0;
	int yp = 0;

	Context context;
	public AnimePanel(Context context) {
		super(context);
		// TODO Auto-generated constructor stub
		this.context = context;
		bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.icon);
		thread = new ViewThread(this);
		
		setOnTouchListener(this);
		getHolder().addCallback(this);
	}

	@Override
	public void onDraw(Canvas canvas) {
		canvas.drawColor(Color.WHITE);
		//canvas.drawBitmap(bitmap, xp, yp, null);
		
		Road road = new Road(context);
		road.draw(canvas);
	}

	@Override
	public void surfaceChanged(SurfaceHolder holder, int format, int width,
			int height) {
		// TODO Auto-generated method stub

	}

	@Override
	public void surfaceCreated(SurfaceHolder holder) {
		// TODO Auto-generated method stub
		if (!thread.isAlive()) {
			thread = new ViewThread(this);
			thread.setRunning(true);
			thread.start();
		}
	}

	@Override
	public void surfaceDestroyed(SurfaceHolder holder) {
		// TODO Auto-generated method stub
		if (thread.isAlive()) {
			thread.setRunning(false);
		}
	}

	@Override
	public boolean onTouch(View v, MotionEvent event) {
		// TODO Auto-generated method stub
		xp = (int) event.getX();
		yp = (int) event.getY();
		return true;
	}
}
